package io.terminus.lego.shinda.web.context

import io.terminus.lego.shinda.web.controller.dto.UserDTO

/**
 * 用户信息上下文
 * @author wangmeng
 * @date 2018/4/26
 */
object UserContext {
    val SESSION_KEY = "UC_CURRENT_USER"
    private val _user = ThreadLocal<UserDTO?>()

    fun setCurrentUser(user: UserDTO) {
        _user.set(user)
    }

    fun getCurrentUser(): UserDTO? {
        return _user.get()?.copy()
    }

    fun getCurrentUserId(): Long? {
        return _user.get()?.id
    }

    fun clear() {
        _user.remove()
    }
}